package com.github.baichuan.application.scaffold.rest.dto.membership;

import com.github.baichuan.mapping.Mapping;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

@Schema(title = "修改用户信息表单")
@Getter
@Setter
public class EditForm {
    @Mapping("member.loginName")
    @Schema(title = "登录名", accessMode = Schema.AccessMode.READ_ONLY)
    private String loginName;

    @Schema(title = "姓名", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotBlank(message = "姓名不能为空")
    @Size(max = 16, message = "姓名长度不能大于16个字符")
    @Mapping("member.name")
    private String name;

    @Schema(title = "用户类型", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotBlank(message = "用户类型不能为空")
    @Mapping
    private String memberType;

    @Schema(title = "所属机构")
    @Mapping("org.uid")
    private String orgUid;

    @Schema(title = "过期日期", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotBlank(message = "过期日期不能为空")
    @Pattern(regexp = "^\\d{4}-\\d{2}-\\d{2}$", message = "过期日期错误")
    @Mapping(format = "yyyy-MM-dd")
    private String expire;

    @Schema(title = "角色", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotEmpty(message = "角色不能为空")
    private List<String> roles;

    @Schema(title = "邮箱")
    @Pattern(regexp = "^(\\w+(?:\\.{0,1}[\\w-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*\\.[a-zA-Z]+|\\s*)$", message = "邮箱格式错误")
    @Mapping("member.email")
    private String email;

    @Schema(title = "手机号")
    @Pattern(regexp = "^(\\d{11}|\\s*)$", message = "手机号格式错误")
    @Mapping("member.mobile")
    private String mobile;
}
